import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

//服务器端 ： 接受到的数据写入文本文件，给出反馈
public class TCP_Demo3_server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(10002);
        Socket accept = serverSocket.accept();//接收客户端的Socket对象
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(accept.getInputStream()));
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("D:\\JavaLearn\\idea\\Code\\JavaSE_Code\\MyNet\\src\\tmp\\copy.txt"));
        String line;
        while((line = bufferedReader.readLine()) != null){
            bufferedWriter.write(line);
            bufferedWriter.newLine();
            bufferedWriter.flush();
        }

        //发送反馈信息

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        writer.write("server had gotten the message...");
        writer.newLine();
        writer.flush();
        serverSocket.close();
        bufferedWriter.close();
    }
}
